//
// Created by ta&to on 2022/8/25.
//

#ifndef TCPSERVER_TCP_ATOMIC_H
#define TCPSERVER_TCP_ATOMIC_H
#include <sys/types.h>

typedef volatile int   tcp_atomic_t;

#define ngx_memory_barrier()

// 比較並替換函數
static inline int tcp_atomic_cmp_set(tcp_atomic_t *lock, int old, int set)
{
    if((*lock) != old)
        return 0;
    else
        *lock = set;
    return 1;
}
#define tcp_trylock(lock) ((*lock) == 0 && tcp_atomic_cmp_set(lock, 0 , 1))
#define tcp_unlock(lock) (*lock) = 0
#endif //TCPSERVER_TCP_ATOMIC_H
